package org.deltaset.secured.dashboard;

import javax.annotation.ManagedBean;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;
import org.springframework.context.annotation.Scope;
import org.springframework.web.context.WebApplicationContext;

/**
 *
 * @author dmakariev
 */
@ManagedBean
@Scope(WebApplicationContext.SCOPE_REQUEST)
public class FileUploadController {

    private UploadedFile file;

    public UploadedFile getFile() {
        return file;
    }

    public void setFile(UploadedFile file) {
        this.file = file;
    }

    public void upload() {
        FacesMessage msg = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

    public void handleFileUpload(FileUploadEvent event) {
        final String fileName = event.getFile().getFileName();
        FacesMessage msg = new FacesMessage("Succesful",  fileName + " is uploaded.");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    
    public String getSomething(){
        return "something";
    }
}
